package com.delivery.deliverysystem.common;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * 使用了redis缓存去处理登录的会话信息
 * (限制了同一管理员用户不能同时登录)
 */
@Component
public class UserLoginCacheManager {
    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    public void cacheUserLogin(String username) {
        redisTemplate.opsForValue().set(username, "loggedin");
    }

    public void removeUserLogin(String username) {
        redisTemplate.delete(username);
    }

    public boolean isUserLoggedIn(String username) {
        return redisTemplate.hasKey(username);
    }
}
